    $(document).ready(function(){
        setStyle("chat");
        
        $.mobile.loading('show');   
        var http = "http://anibox.me/api.php?task=chat_messages&count=20&offset=0";
        $.getJSON(http, parseJson);
        
    });

    function parseJson(data){
        for (var i in data) {
            $('#list').append(
                '<li>' +
                '<div class="div_style_update">'+
                 data[i].message +
                 '</div>'+
                 '<p"><font size="+1" color="red">'+ data[i].author + '</font>:  '+ data[i].date+' МСК</p>'+
                '</li>\n'
            );
        }
        $('#list').listview('refresh');
        $.mobile.loading('hide');
    }
    
    function butPress(){
    	var mess = document.getElementById("message").value;
    	if (mess == ''){
    		alert('Введите сообщение,');
    	}
    
    	var log = window.localStorage.getItem("login");
    	if (log == null){
    		var log = window.sessionStorage.getItem("login");
    		if(log == null){
    			alert('вы не авторизованы');
    			return;
    		}else{
    			var pas = window.sessionStorage.getItem("password");
    		}
    	}else{
			var pas = window.localStorage.getItem("password");
    	}	
    	
    	    
    		var http = "http://anibox.me/api.php?task=add_chat_message&name="+log+"&password="+pas+"&message="+mess;
        	$.getJSON(http, sendJSON);
    }
    
    function sendJSON(data){
    	location.reload();  
    }
    